package com.wanxi.service.Impl;

import com.wanxi.dao.Impl.ServiceTypeDaoImpl;
import com.wanxi.dao.ServiceTypeDao;
import com.wanxi.dto.ResultDto;
import com.wanxi.model.ServiceTypeModel;
import com.wanxi.service.ServiceTypeService;

/**
 * @author Li
 * @Date 2023/5/7 19:31
 */
public class ServiceTypeServiceImpl implements ServiceTypeService {
    private ServiceTypeDao serviceTypeDao = new ServiceTypeDaoImpl();
    public ResultDto add(ServiceTypeModel serviceTypeModel) {
        boolean same = serviceTypeDao.findSameName(serviceTypeModel);
        if (same){
            return ResultDto.builder()
                    .code(0)
                    .msg("用户名已存在")
                    .build();
        }
        return ResultDto.builder()
                .code(0)
                .msg("新增成功")
                .count(serviceTypeDao.add(serviceTypeModel))
                .build();
    }

    public ResultDto update(ServiceTypeModel serviceTypeModel) {
//        boolean same = serviceTypeDao.findSameName(serviceTypeModel);
//        if (same){
//            return ResultDto.builder()
//                    .code(0)
//                    .msg("用户名已存在")
//                    .build();
//        }
        return ResultDto.builder()
                .code(200)
                .msg("修改成功")
                .count(serviceTypeDao.update(serviceTypeModel))
                .build();
    }

    public ResultDto delete(ServiceTypeModel serviceTypeModel) {
        return ResultDto.builder()
                .code(0)
                .msg("删除成功")
                .count(serviceTypeDao.delete(serviceTypeModel))
                .build();
    }

    public ResultDto findAll(ServiceTypeModel serviceTypeModel) {
        return ResultDto.builder()
                .code(0)
                .msg("查询成功")
                .count(serviceTypeDao.count(serviceTypeModel))
                .data(serviceTypeDao.findAll(serviceTypeModel))
                .build();
    }

    public ResultDto findById(ServiceTypeModel serviceTypeModel) {
        return ResultDto.builder()
                .code(0)
                .msg("查询成功")
                .data(serviceTypeDao.findById(serviceTypeModel))
                .build();
    }

    @Override
    public Integer totalCount() {
        return null;
    }
}
